package com.qx.entity;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import com.fasterxml.jackson.annotation.JsonIgnore;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Entity
@Data
@Table(name="users")
public class Users {
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private Integer id;
	private String loginname;
	private String password;
	private String islockout;
	private String lastlogintime;
	private String psdwrongtime;
	private String locktime;
	private String protectemail;
	private String protectmtel;
	private String createtime;

	@JsonIgnore
	//指定多对多关系，默认懒加载，只有调用getter方法时才加载数据
	@ManyToMany(fetch=FetchType.LAZY)
	@JoinTable(name="userroles",//指定第三张中间表名称
	joinColumns= {@JoinColumn(name="userid")},//本表主键
	inverseJoinColumns= {@JoinColumn(name="roleid")})//多对多关系另一张表
	//NotFound:意思是找不到引用的外键数据时忽略，NotFound默认是exception
	@NotFound(action=NotFoundAction.IGNORE)
	//private List<Roles> rlist = new ArrayList<Roles>();
	private Set<Roles> roleSet = new HashSet<Roles>();

	
	public String test() {
		return "Users [id=" + id + ", loginname=" + loginname + ", password=" + password + ", islockout=" + islockout
				+ ", lastlogintime=" + lastlogintime + ", psdwrongtime=" + psdwrongtime + ", locktime=" + locktime
				+ ", protectemail=" + protectemail + ", protectmtel=" + protectmtel + ", createtime=" + createtime
				+ ", roleSet=" + roleSet + "]";
	}


	@Override
	public String toString() {
		return "Users [id=" + id + ", loginname=" + loginname + ", password=" + password + ", islockout=" + islockout
				+ ", lastlogintime=" + lastlogintime + ", psdwrongtime=" + psdwrongtime + ", locktime=" + locktime
				+ ", protectemail=" + protectemail + ", protectmtel=" + protectmtel + ", createtime=" + createtime
				+ "]";
	}
	
	
	
}

	
	
	
	